package cn.tedu.loding.controller;


import cn.tedu.loding.pojo.dto.BannerAddNewDTO;
import cn.tedu.loding.pojo.vo.BannerListItemVO;
import cn.tedu.loding.service.IBannerService;
import cn.tedu.loding.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/banner")
@Api(tags = "12.轮播图管理模板")
@RestController
public class BannerController {

    @Autowired
    IBannerService bannerService;

    @ApiOperation("添加轮播图")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated BannerAddNewDTO bannerAddNewDTO){
        log.debug("开始处理【添加轮播图】的请求，参数：{}", bannerAddNewDTO);
        bannerService.addNew(bannerAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询轮播图列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<BannerListItemVO>> list() {
        List<BannerListItemVO> list = bannerService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("删除轮播图")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id",value = "轮播图id",required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理【删除轮播图】的请求，参数：{}",id);
        System.out.println("开始删除:"+id);
        bannerService.delete(id);
        log.debug("测试");
        return JsonResult.ok();
    }
}
